package com.business.system.official.toursism.websiteshop.manager.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.business.system.official.toursism.websitegoods.entity.WebsiteGoods;
import com.business.system.official.toursism.websitegoods.manager.WebsiteGoodsManager;
import com.business.system.official.toursism.websiteshop.entity.WebsiteShop;
import com.business.system.official.toursism.websiteshop.manager.WebsiteShopManager;
import com.business.system.official.toursism.websiteshop.mapper.WebsiteShopMapper;
import com.business.system.official.toursism.websiteshop.vo.WebsiteShopBriefListVO;
import com.business.system.official.toursism.websiteshop.vo.WebsiteShopBriefVO;
import com.business.system.official.toursism.websiteshop.vo.WebsiteShopDetailListVO;
import com.business.system.official.toursism.websiteshop.vo.WebsiteShopDetailVO;
import com.business.system.official.toursism.websiteshop.vo.data.WebsiteShopBriefData;
import com.business.system.official.toursism.websiteshop.vo.data.WebsiteShopDetailData;
import com.seed.core.exception.ManagerException;
import com.seed.core.pojo.manager.impl.SeedSystemManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @description 购物车
 * @author CodeGenerator
 * @date   2025-01-25
 * @version V1.0
 */
@Slf4j
@Transactional(rollbackFor = ManagerException.class)
@Service("websiteShopManager")
public class WebsiteShopManagerImpl extends SeedSystemManagerImpl<WebsiteShopMapper, WebsiteShop> implements WebsiteShopManager {
    @Autowired
    private ISysUserService userService;
    @Autowired
    private WebsiteGoodsManager websiteGoodsManager;

    /**
     * 根据id获取详情VO data
     *
     * @param websiteShopId 对象id
     * @return 详情VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopDetailData convertDetailData(String websiteShopId) throws ManagerException {
        WebsiteShop websiteShop = this.getById(websiteShopId);
        return this.convertDetailData(websiteShop);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteShop model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopDetailData convertDetailData(WebsiteShop websiteShop) throws ManagerException {
        WebsiteShopDetailData websiteShopDetailData = new WebsiteShopDetailData();
        try {
            BeanUtils.copyProperties(websiteShop, websiteShopDetailData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteShop);
        }
        // 获取购买人姓名
        SysUser sysUser = userService.getById(websiteShopDetailData.getUserId());
        websiteShopDetailData.setUserName(sysUser.getRealname());
        // 获取商品单价
        WebsiteGoods goods = websiteGoodsManager.getById(websiteShopDetailData.getGoodsId());
        websiteShopDetailData.setGoodsPrice(goods.getGoodsPrice());
        return websiteShopDetailData;
    }

    /**
     * 根据id获取详情VO
     *
     * @param websiteShopId 对象id
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopDetailVO getDetailVO(String websiteShopId) throws ManagerException {
        WebsiteShopDetailData websiteShopDetailData = this.convertDetailData(websiteShopId);
        return new WebsiteShopDetailVO(websiteShopDetailData);
    }

    /**
     * 根据对象获取详情VO
     *
     * @param websiteShop 对象
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopDetailVO getDetailVO(WebsiteShop websiteShop) throws ManagerException {
        WebsiteShopDetailData websiteShopDetailData = this.convertDetailData(websiteShop);
        return new WebsiteShopDetailVO(websiteShopDetailData);
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteShopDetailData> getConvertDetailListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteShop> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteShop::getId, ids);
        List<WebsiteShop> websiteShopList = this.list(queryWrapper);
        return this.listConvertDetailData(websiteShopList);
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteShopDetailData> listConvertDetailData(Wrapper<WebsiteShop> queryWrapper) throws ManagerException {
        List<WebsiteShop> websiteShopList = this.list(queryWrapper);
        return this.listConvertDetailData(websiteShopList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteShopList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteShopDetailData> listConvertDetailData(List<WebsiteShop> websiteShopList) throws ManagerException {
        List<WebsiteShopDetailData> websiteShopDetailDataList = new ArrayList<>();
        for (WebsiteShop websiteShop : websiteShopList) {
            websiteShopDetailDataList.add(this.convertDetailData(websiteShop));
        }
        return websiteShopDetailDataList;
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopDetailListVO getDetailListVOByIds(List<String> ids) throws ManagerException {
        return new WebsiteShopDetailListVO(this.getConvertDetailListVOByIds(ids));
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopDetailListVO getDetailListVO(Wrapper<WebsiteShop> queryWrapper) throws ManagerException {
        return new WebsiteShopDetailListVO(this.listConvertDetailData(queryWrapper));
    }

    /**
     * 根据对象list获取详情VO data list
     *
     * @param websiteShopList 对象list
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopDetailListVO getDetailListVO(List<WebsiteShop> websiteShopList) throws ManagerException {
        return new WebsiteShopDetailListVO(this.listConvertDetailData(websiteShopList));
    }

    /**
     * 根据id获取简略VO data
     *
     * @param websiteShopId 对象id
     * @return 简略VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopBriefData convertBriefData(String websiteShopId) throws ManagerException {
        WebsiteShop websiteShop = this.getById(websiteShopId);
        return this.convertBriefData(websiteShop);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteShop model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopBriefData convertBriefData(WebsiteShop websiteShop) throws ManagerException {
        WebsiteShopBriefData websiteShopBriefData = new WebsiteShopBriefData();
        try {
            BeanUtils.copyProperties(websiteShop, websiteShopBriefData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteShop);
        }
        return websiteShopBriefData;
    }

    /**
     * 根据id获取简略VO
     *
     * @param websiteShopId 对象id
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopBriefVO getBriefVO(String websiteShopId) throws ManagerException {
        WebsiteShopBriefData websiteShopBriefData = this.convertBriefData(websiteShopId);
        return new WebsiteShopBriefVO(websiteShopBriefData);
    }

    /**
     * 根据对象获取简略VO
     *
     * @param websiteShop 对象
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopBriefVO getBriefVO(WebsiteShop websiteShop) throws ManagerException {
        WebsiteShopBriefData websiteShopBriefData = this.convertBriefData(websiteShop);
        return new WebsiteShopBriefVO(websiteShopBriefData);
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteShopBriefData> listConvertBriefDataByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteShop> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteShop::getId, ids);
        List<WebsiteShop> websiteShopList = this.list(queryWrapper);
        return this.listConvertBriefData(websiteShopList);
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteShopBriefData> listConvertBriefData(Wrapper<WebsiteShop> queryWrapper) throws ManagerException {
        List<WebsiteShop> websiteShopList = this.list(queryWrapper);
        return this.listConvertBriefData(websiteShopList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteShopList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteShopBriefData> listConvertBriefData(List<WebsiteShop> websiteShopList) throws ManagerException {
        List<WebsiteShopBriefData> websiteShopBriefDataList = new ArrayList<>();
        for (WebsiteShop websiteShop : websiteShopList) {
            websiteShopBriefDataList.add(this.convertBriefData(websiteShop));
        }
        return websiteShopBriefDataList;
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopBriefListVO getBriefListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteShop> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteShop::getId, ids);
        List<WebsiteShop> websiteShopList = this.list(queryWrapper);
        return new WebsiteShopBriefListVO(this.listConvertBriefData(websiteShopList));
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopBriefListVO getBriefListVO(Wrapper<WebsiteShop> queryWrapper) throws ManagerException {
        List<WebsiteShop> websiteShopList = this.list(queryWrapper);
        return new WebsiteShopBriefListVO(this.listConvertBriefData(websiteShopList));
    }

    /**
     * 根据对象list获取简略VO data list
     *
     * @param websiteShopList 对象list
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteShopBriefListVO getBriefListVO(List<WebsiteShop> websiteShopList) throws ManagerException {
        return new WebsiteShopBriefListVO(this.listConvertBriefData(websiteShopList));
    }
}
